<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <!--{include file='comm/header.tpl'}-->
    <!--{include file='comm/comm_editor.tpl'}-->
    <!--{include file='comm/comm_region.tpl'}-->
    <!--{include file='comm/comm_cal.tpl'}-->
    <!--{include file="comm/comm_multiselect.tpl"}-->

    <title>订单分配</title>
</head>
<style>
    .ui-multiselect{ width: 165px !important;}
</style>
<body>

<div class="container">
    
        <div class="comm_content">

            <div class="search-box">
                <div style="position:relative">
                    <form id="search_form" class="form-inline" onsubmit="return false;">
                        <table>
                            <tbody>
                            <tr>
                                <td>
                                    <span>配送日期：<input id="send_date" class="form-control input-sm"  name="send_date" value="<!--{$currentDate|default:''}-->" type='text' style="width:100px;" readonly ></span>
                                    <button type="button" class="btn btn-default btn-sm" onclick="orderAllocation.timeClear();">清 空</button>

                                     <span>配送开始时间：<select id="send_start_time" class="form-control input-sm"  name="send_start_time" style="width:100px;">
                                             <option value="">请选择</option>
                                             <!--{foreach from=$sendStartTime_array key=myId item=star}-->
                                             <!--{if $myId == 0}-->
                                             <option value="<!--{$star.itemName}-->" selected><!--{$star.itemName}--></option>
                                             <!--{/if}-->
                                             <option value="<!--{$star.itemName}-->" ><!--{$star.itemName}--></option>
                                             <!--{/foreach}-->
                                         </select>
                                    </span>

                                    <span>配送结束时间：<select id="send_start_time_end" class="form-control input-sm"  name="send_start_time_end" style="width:100px;">
                                            <option value="">请选择</option>
                                            <!--{foreach from=$sendStartTime_array item=end}-->
                                            <!--{if $end.itemName == $end_time}-->
                                            <option value="<!--{$end.itemName}-->" selected><!--{$end.itemName}--></option>
                                            <!--{/if}-->
                                            <option value="<!--{$end.itemName}-->"><!--{$end.itemName}--></option>
                                            <!--{/foreach}-->
                                        </select>
                                    </span>

                                    <span>订单编号：<input type="text" id="bill_code" class="form-control input-sm"  name="bill_code" value="" style="width:177px;"/></span>

                                    <span>
                                        配送对账：<select id="is_reconciliation" class="form-control input-sm"  name="is_reconciliation" style="width:100px;">
                                            <option value="">请选择</option>
                                            <option value="1">是</option>
                                            <option value="0">否</option>
                                        </select>
                                    </span>

                                     <span>
                                        是否有应收：<select id="receivable" class="form-control input-sm"  name="receivable" style="width:100px;">
                                             <option value="">请选择</option>
                                             <option value="1">是</option>
                                             <option value="0">否</option>
                                         </select>
                                    </span>


                                     <span>城市：<select id="deliver_cityid" class="form-control input-sm"  name="deliver_cityid" style="width:100px;">
                                             <option value="">请选择</option>
                                         </select>
                                    </span>
                                    <input type="hidden" name="deliver_cityid_hide" id="deliver_cityid_hide" value="">

                                    <span>配送站：<select id="distribution_id" class="form-control input-sm"  name="distribution_id" style="width:120px;">
                                            <option value="">请选择</option>
                                        </select>
                                    </span>
                                    <input type="hidden" name="distribution_id_hide" id="distribution_id_hide" value="">

                                    <span>
                                        配送员：<select id="distribution_technician_id" class="form-control input-sm"  name="distribution_technician_id" style="width:100px;">
                                            <option value="">请选择</option>
                                        </select>
                                    </span>

                                     <span>
                                        是否分配配送员：<select id="technician_id" class="form-control input-sm"  name="technician_id" style="width:100px;">
                                             <option value="">请选择</option>
                                             <option value="1">是</option>
                                             <option value="0">否</option>
                                         </select>
                                    </span>

                                    <span>订单类型：<select id="billType" class="form-control input-sm"  name="billType" style="width:120px;">
                                            <option value="all">全部</option>
                                            <!--{foreach from=$global_array.bill_type item=bill_type_name key=bill_type}-->
                                                <option value="<!--{$bill_type}-->"><!--{$bill_type_name.name}--></option>
                                            <!--{/foreach}-->
                                        </select>
                                    </span>
                                    <input type="hidden" id="bill_type" name="bill_type" value=""/>

                                    <span>订单状态：<select id="bill_status" class="form-control input-sm"  name="bill_status" style="width:120px;">
                                            <option value="all">全部</option>
                                            <!--mod by yim.hu 20141127 FUN-BK-0030 订单分配页面增加标识退货的订单--start -->
                                            <option value="1">已确认</option>
                                            <option value="2">已打印生产单</option>
                                            <option value="3">已质检入库</option>
                                            <option value="4">已上车</option>
                                            <option value="5">已下车</option>
                                            <option value="6">已经出仓</option>
                                            <!--mod by yim.hu 20141127 FUN-BK-0030 订单分配页面增加标识退货的订单--end -->
                                        </select>
                                    </span>

                                    <input type="hidden" id="billStatus" name="billStatus" value=""/>

                                    <span>
                                        订单品牌：<select class="form-control input-sm" name="billPlatform">
                                            <option value="all">全部</option>
                                            <option value="1">自营</option>
                                            <option value="2">澳粒</option>
                                            <option value="3">下午茶</option>
                                        </select>
                                    </span>

                                     <span>
                                        发票：<select id="invoice" class="form-control input-sm"  name="invoice" style="width:100px;">
                                             <option value="">请选择</option>
                                             <option value="1">是</option>
                                             <option value="0">否</option>
                                         </select>
                                    </span>
                                    <span>下单日期：
                                        <input type="text" class="form-control input-sm" readonly style="width:105px" value="" name="createDate" id="createDate">
                                    </span>
                                    <input type="button" value="查询" class="btn btn-primary" onclick="orderAllocation.search();" />
                                    <input type="button" value="重置" class="btn btn-warning" onclick="orderAllocation.clear();" />
                                </td>

                            </tr>
                            </tbody>
                        </table>
                    </form>
                </div>
            </div>

            <table id="flex" style="display:none"></table>

        </div>


    <!--{include file='comm/footer.tpl'}-->

</div>


<div id="pop" style="display: none">
    <div class="panel">

        <div class="panel-body">

            <form id="item_form" onsubmit="return false;" class="form-horizontal">


                <div class="form-group">
                    <label class="col-sm-3 control-label" for="distribution_technician_id_up">
                        <span class="red">*</span>
                        配送员：
                    </label>
                    <div class="col-sm-9">
                        <select class="form-control w150" id="distribution_technician_id_up" onchange="orderAllocation.showMobile();"  name="distribution_technician_id">
                            <option value="">请选择</option>

                        </select>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-sm-3 control-label" for="mobile">
                        <span class="red">*</span>
                        手机号码：
                    </label>
                    <div class="col-sm-9">
                        <input id="mobile_up" class="form-control w150" type="text" readonly placeholder="请先选择配送员" name="mobile">
                    </div>
                </div>

            </form>

        </div>

    </div>
</div>


<div id="pop_up" style="display: none">
    <div class="panel">

        <div class="panel-body">

            <form id="distribution_form" onsubmit="return false;" class="form-horizontal">


                <div class="form-group">
                    <label class="col-sm-3 control-label" for="distribution_id_up">
                        <span class="red">*</span>
                        配送站：
                    </label>
                    <div class="col-sm-9">
                        <select class="form-control w150" id="distribution_id_up"   name="distribution_id_up">

                        </select>
                    </div>
                </div>

            </form>

        </div>

    </div>
</div>


<script type="text/javascript">

    $('#send_date').datepicker();
    $('#createDate').datepicker();

    var table_id = <!--{$table_id}-->;

    var fixed_json = <!--{$fixed_json}-->;

    $("#flex").flexigrid({
        url:"/invokingAjax-backend/send/orderAllocation.ajax?operFlg=1",
        dataType: "json",
        colModel : fixed_json,
        <!--{if $edit_permission}-->
        buttons : [
            {name: "批量分配", bclass: "cancelCheckAll", onpress : "orderAllocation.batchAllocationCheck"},
            {separator: true},
            {name: "分配修改 ", bclass: "cancelCheckAll", onpress : "orderAllocation.AllocationEdit"},
            {separator: true},
            {name: "分单调度", bclass: "cancelCheckAll", onpress : "orderAllocation.submenuChange"}
        ],
        <!--{/if}-->
        sortname: "createTime ,send_start_time,distribution_technician_id",
        sortorder: "desc",
        usepager: true,
        rp: 50,
        useRp: true,
        showTableToggleBtn: true,
        autoload: false,//初始不显示
        onSubmit: function() {
            var dt = $('#search_form').serializeArray();
            $("#flex").flexOptions({params: dt});
            return true;
        },

        //拉伸宽度后触发
        onColResize:function(){

            var last_cid = arguments[0];
            var width = arguments[1];

            E.ajax_get({
                url:'/invokingAjax-backend/system/flexigrid.ajax?operFlg=1',
                data:{
                    table_id:table_id,
                    last_cid:last_cid,
                    width:width
                },
                call:function( o ){ }

            });

        },

        //隐藏后触发
        onToggleCol:function(){

            var cid = arguments[0];
            var hide = arguments[1];

            E.ajax_get({
                url:'/invokingAjax-backend/system/flexigrid.ajax?operFlg=3',
                data:{
                    table_id:table_id,
                    cid:cid,
                    hide:hide
                },
                call:function( o ){ }

            });
        },

        //拖拽后触发
        onDragCol:function(){

            var cid = arguments[0];
            var last_cid = arguments[1];

            E.ajax_get({
                url:'/invokingAjax-backend/system/flexigrid.ajax?operFlg=2',
                data:{
                    table_id:table_id,
                    cid:cid,
                    last_cid:last_cid
                },
                call:function( o ){ }

            });

        }

    });

    $(document).on('click',"#allChecked", function(){
        if( this.checked ){
            //全选
            $("input[name='billArr[]']").each(function(){
                this.checked = true;
            })
        }else{
            //全不选
            $("input[name='billArr[]']").each(function(){
                this.checked = false;
            })
        }
    });


    $('#billType').multiselect();
    $('#bill_status').multiselect();

    var orderAllocation = {
        billNoArr:'',//订单号数组
        //搜索
        search: function() {
            $deliver_cityid = $('#deliver_cityid').val()
            $('#deliver_cityid_hide').val($deliver_cityid);
            $distribution_id = $('#distribution_id').val()
            $('#distribution_id_hide').val($distribution_id);
            var billType_values = $("#billType").multiselect("getChecked").map(function(){ return this.value;}).get();
            $('#bill_type').val(billType_values);
            var bill_status_values =  $("#bill_status").multiselect("getChecked").map(function(){ return this.value;}).get();
            $('#billStatus').val(bill_status_values);

            var dt = $('#search_form').serializeArray();
            $("#flex").flexOptions({newp: 1, params: dt}).flexReload();
        },

        //重置
        clear: function(){
            document.forms['search_form'].reset();
            $('#billType').multiselect("refresh");
            $('#bill_status').multiselect("refresh");
            this.search();
        },

        timeClear: function() {
            $('#send_date').val('');
        },

        //重新加载
        load: function() {
            $("#flex").flexReload();
        },

        //订单详情
        billview: function( bill_no ) {
            window.open('/quanliadmin/app/bill/billSearch.pscript?operFlg=9&bill_no=' + bill_no);
        },

        /**
         * ========================================
         * 批量分配start
         * ========================================
         */

        //批量分配
        batchAllocationCheck:function(){

            //var selected_count = $('.trSelected',flex).length;//获取选中的行的行数

            var distribution_id = $('#distribution_id_hide').val();//配送站id

            var error_msg = ''; //错误信息

            if(distribution_id == ''){
                error_msg += '请在查询条件里选择城市和配送站进行查询后再使用本操作<br>';
            }

            var tempArr = new Array(); //批量分配的订单号

            $("input[name='billArr[]']").each(function(){
                if (this.checked) {
                    tempArr.push($(this).val());
                }
            });

            if (tempArr.length == 0) {     //判断是否选中复选框，如果没有选择提示相应信息
                error_msg += '请选择要批量分配的数据';
            }


            if(error_msg){
                E.alert(error_msg);
            }else{

                this.billNoArr = tempArr;

                E.loadding.open('正在加载配送员，请稍候...');

                //查询订单主表信息 校验数据
                E.ajax_post({
                    url: '/invokingAjax-backend/send/orderAllocation.ajax?operFlg=2',
                    data: {
                        distribution_id:distribution_id,
                        billNoArr: orderAllocation.billNoArr
                    },
                    call: function( o ) {
                        if(o.code == 200){
                            orderAllocation.callBack();
                        }else{
                            E.loadding.close();
                            E.alert(o.message);
                        }

                    }
                });


            }

        },


        //批量分配校验成功回调
        callBack:function(){

            var distribution_id = $('#distribution_id').val();//配送站id

            //获得配送员信息
            E.ajax_post({
                url: '/invokingAjax-backend/send/orderAllocation.ajax?operFlg=3',
                data: {
                    distribution_id: distribution_id
                },
                call: function( o ) {

                    if (o.code == 200) {

                        E.popup.open({
                            id: 'pop',
                            title: '批量分配',
                            css: 'width: 600px;',
                            btnName: '保存',
                            btnCall: 'orderAllocation.allocationExecute();'
                        });

                        var html ='';
                        var data = o.data;
                        var countArr =  data.length;
                        for(var i=0;i<countArr;i++){
                            html += '<option  id="option_"+data[i].distribution_technician_id  value=" '+ data[i].distribution_technician_id +'">';
                            html += '' + data[i].distribution_technician_name +''
                            html += '</option>';
                        }

                        $('#distribution_technician_id_up').append(html);

                    }

                    E.loadding.close();

                }
            });

        },

        //弹出层中选择配送员联动获得配送员手机号
        showMobile:function (){
            var distribution_technician_id = $('#distribution_technician_id_up').val();//配送员id
            if(distribution_technician_id == ''){
                $('#mobile_up').val('');
                E.alert('请先选择配送员');
            }
            E.ajax_post({
                url: '/invokingAjax-backend/send/orderAllocation.ajax?operFlg=4',
                data: {
                    distribution_technician_id: distribution_technician_id
                },
                call: function( o ) {

                    if (o.code == 200) {

                        $('#mobile_up').val(o.data[0].mobile);

                    }

                }
            });

        },

        //批量分配校验
        allocationExecute:function(){
            var distribution_technician_id = $('#distribution_technician_id_up').val();//配送员id
            var distribution_technicia = $('#distribution_technician_id_up').find('option:selected').text();//配送员名称
            var mobile = $('#mobile_up').val();//手机号
           // alert(distribution_technician_id);
            if (distribution_technician_id == '') {
                E.alert('请先选择配送员');
            }else{
                orderAllocation.allocationExcutionRes();
            }



        },

        //批量分配执行
        allocationExcutionRes:function(){
            var distribution_technician_id = $('#distribution_technician_id_up').val();//配送员id
            var distribution_technicia = $('#distribution_technician_id_up').find('option:selected').text();//配送员名称
            var mobile = $('#mobile_up').val();//手机号
            E.loadding.open('正在分配配送员，请稍候...');
            E.ajax_post({
                url: '/invokingAjax-backend/send/orderAllocation.ajax?operFlg=5',
                data: {
                    distribution_technician_id: distribution_technician_id,
                    mobile:mobile,
                    distribution_technicia:distribution_technicia,
                    billNoArr :orderAllocation.billNoArr
                },
                call: function( o ) {
                    E.loadding.close();
                    if (o.code == 200) {
                        E.popup.close();
                        E.alert("批量分配成功",2);
                        orderAllocation.load();
                    }else{
                        E.alert(o.message);
                    }
                }
            });
        },


        /**
         * ========================================
         * 批量分配end
         * ========================================
         */

        /**
         * ========================================
         * 分配修改start
         * ========================================
         */

        //分配修改
        AllocationEdit:function(){
            this.billNoArr = '';

            var distribution_id = $('#distribution_id_hide').val();//配送站id

            var error_msg = ''; //错误信息

            if(distribution_id == ''){
                error_msg += '请在查询条件里选择城市和配送站进行查询后再使用本操作<br>';
            }

            var tempArr = new Array(); //分配修改的订单号

            $("input[name='billArr[]']").each(function(){
                if (this.checked) {
                    tempArr.push($(this).val());
                }
            });

            if (tempArr.length == 0) {     //判断是否选中复选框，如果没有选择提示相应信息
                error_msg += '请选择要分配修改的数据';
            }


            if(error_msg){
                E.alert(error_msg);
            }else{
                this.billNoArr = tempArr;

                E.loadding.open('正在加载配送员，请稍候...');

                //查询订单主表信息 校验数据
                E.ajax_post({
                    url: '/invokingAjax-backend/send/orderAllocation.ajax?operFlg=6',
                    data: {
                        distribution_id:distribution_id,
                        billNoArr: orderAllocation.billNoArr
                    },
                    call: function( o ) {
                        if(o.code == 200){
                            orderAllocation.callBackEdit(o.data);
                        }else{
                            E.loadding.close();
                            E.alert(o.message);
                        }

                    }
                });


            }

        },


        //分配修改校验成功回调
        callBackEdit:function( arg ){

            var distribution_id = $('#distribution_id').val();//配送站id


            //获得配送员信息
            E.ajax_post({
                url: '/invokingAjax-backend/send/orderAllocation.ajax?operFlg=3',
                data: {
                    distribution_id: distribution_id
                },
                call: function( o ) {

                    if (o.code == 200) {

                        E.popup.open({
                            id: 'pop',
                            title: '分配修改',
                            css: 'width: 600px;',
                            btnName: '保存',
                            btnCall: 'orderAllocation.editAllocationExecute();'
                        });

                        var html ='';
                        var data = o.data;
                        var countArr =  data.length;
                        for(var i=0;i<countArr;i++){
                            html += '<option  id="option_"+data[i].distribution_technician_id  value=" '+ data[i].distribution_technician_id +'">';
                            html += '' + data[i].distribution_technician_name +''
                            html += '</option>';
                        }

                        $('#distribution_technician_id_up').append(html);

                    }

                    E.loadding.close();

                }
            });

        },

        //弹出层中选择配送员联动获得配送员手机号
        showMobile:function (){
            var distribution_technician_id = $('#distribution_technician_id_up').val();//配送员id
            if(distribution_technician_id == ''){
                $('#mobile_up').val('');
                E.alert('请先选择配送员');
            }
            E.ajax_post({
                url: '/invokingAjax-backend/send/orderAllocation.ajax?operFlg=4',
                data: {
                    distribution_technician_id: distribution_technician_id
                },
                call: function( o ) {

                    if (o.code == 200) {

                        $('#mobile_up').val(o.data[0].mobile);

                    }

                }
            });

        },

        //分配修改执行
        editAllocationExecute:function(){
            var distribution_technician_id = $('#distribution_technician_id_up').val();//配送员id
            var distribution_technicia = $('#distribution_technician_id_up').find('option:selected').text();//配送员名称
            var mobile = $('#mobile_up').val();//手机号

            if (distribution_technician_id == '') {
                E.alert('请先选择配送员');
            }else{
                E.loadding.open('正在修改配送员，请稍候...');
                E.ajax_post({
                    url: '/invokingAjax-backend/send/orderAllocation.ajax?operFlg=7',
                    data: {
                        distribution_technician_id: distribution_technician_id,
                        mobile:mobile,
                        distribution_technicia:distribution_technicia,
                        billNoArr :orderAllocation.billNoArr
                    },
                    call: function( o ) {
                        E.loadding.close();
                        if (o.code == 200) {
                            E.popup.close();
                            E.alert("分配修改成功",2);
                            orderAllocation.load();
                        }else{
                            E.alert(o.message);
                        }

                    }
                });
            }



        },

        /**
         * ========================================
         * 分配修改end
         * ========================================
         */


        /**
         * ========================================
         * 分单调度start
         * ========================================
         */
        //分单调度校验
        submenuChange:function(){

            var selected_count = $('.trSelected',flex).length;//获取选中的行的行数

            var deliver_cityid  = $('#deliver_cityid_hide').val();//城市id

            var error_msg = ''; //错误信息

            if(deliver_cityid == ''){
                error_msg += '请在查询条件里选择城市进行查询后再使用本操作<br>';
            }


            var tempArr = new Array(); //分单调度的订单号

            $("input[name='billArr[]']").each(function(){
                if (this.checked) {
                    tempArr.push($(this).val());
                }
            });

            if (tempArr.length == 0) {     //判断是否选中复选框，如果没有选择提示相应信息
                error_msg += '请选择要分单调度的数据';
            }

            if(error_msg){
                E.alert(error_msg);
            }else{

                this.billNoArr = tempArr;

                E.loadding.open('正在加载配送站，请稍候...');

                //查询订单主表信息 校验数据
                E.ajax_post({
                    url: '/invokingAjax-backend/send/orderAllocation.ajax?operFlg=8',
                    data: {
                        billNoArr: orderAllocation.billNoArr
                    },
                    call: function( o ) {
                        if(o.code == 200){
                            orderAllocation.submenuCallBack( o.data );
                        }else{
                            E.loadding.close();
                            E.alert(o.message);
                        }

                    }
                });


            }

        },


        //分单调度校验成功回调
        submenuCallBack:function( deliver_cityid ){

            $('#distribution_id_up').html("");

            var distributionHtml = '<option value="">请选择</option>';
            $.ajax({
                type: "post",
                url: "/invokingAjax-comm/bill/distribution.ajax?operFlg=4",
                dataType: "json",
                data: {deliver_cityid: deliver_cityid},
                success: function( obj ) {

                    E.popup.open({
                        id: 'pop_up',
                        title: '分单调度',
                        css: 'width: 600px;',
                        btnName: '保存',
                        btnCall: 'orderAllocation.submenuExecute();'
                    });

                    if(obj.code ==200 && obj.data != null){
                        $.each(obj.data, function(i,val){
                            distributionHtml +='<option value="'+val.distribution_id+'">'+val.distribution_name+'</option>';
                        });
                        $('#distribution_id_up').html(distributionHtml);
                    }else{
                        distributionHtml += '';
                        $('#distribution_id_up').html(distributionHtml);
                    }

                    E.loadding.close();

                }

            });

        },



        //分单调度执行
        submenuExecute:function(){
            var distribution_id  = $('#distribution_id_up').val();//配送站id

            if (distribution_id == '') {
                E.alert('请先选择配送站');
            }else{
                E.loadding.open('正在修改配送站，请稍候...');
                E.ajax_post({
                    url: '/invokingAjax-backend/send/orderAllocation.ajax?operFlg=10',
                    data: {
                        distribution_id: distribution_id,
                        billNoArr :orderAllocation.billNoArr
                    },
                    call: function( o ) {
                        E.loadding.close();
                        if (o.code == 200) {
                            E.popup.close();
                            E.alert("分单调度成功",2);
                            orderAllocation.load();
                        }else{
                            E.alert(o.message);
                        }

                    }
                });
            }

        }
        /**
         * ========================================
         * 分单调度end
         * ========================================
         */

    };



    $(window).ready(function() {

        $("#deliver_cityid").html("");

        var cityHtml = '<option value="">请选择</option>';

        $.ajax({
            type: "post",
            url: "/invokingAjax-comm/bill/distribution.ajax?operFlg=1",
            dataType: "json",
            data: "",
            success: function( result_obj ) {
                if(result_obj.code == 200){
                    var selected = "";
                    if(result_obj.data.length == 1){
                            selected = "selected";
                    }
                    $.each(result_obj.data, function(i,val){
                        cityHtml +='<option value="'+val.id+'" '+selected+'>'+val.name+'</option>';
                    });
                    $('#deliver_cityid').html(cityHtml);
                    $("#deliver_cityid").trigger("change");
                }else{
                    E.alert(result_obj.message);
                }
            }
        });


        //点击城市联动获得配送站
        $(document).on('change', '#deliver_cityid', function() {

            $('#distribution_id').html("");
            $('#distribution_technician_id').html('');

            var deliver_cityid = $('#deliver_cityid').children('option:selected').val();
            var distributionHtml = '<option value="">请选择</option>';
            var technicianHtml = '<option value="">请选择</option>';
            $.ajax({
                type: "post",
                url: "/invokingAjax-comm/bill/distribution.ajax?operFlg=2",
                dataType: "json",
                data: {deliver_cityid: deliver_cityid},
                success: function( obj ) {
                    if(obj.code ==200 && obj.data != null){
                        var selected = "";
                        if(obj.data.length == 1){
                            selected = "selected";
                        }
                        $.each(obj.data, function(i,val){
                            distributionHtml +='<option value="'+val.distribution_id+'" '+selected+'>'+val.distribution_name+'</option>';
                        });
                        $('#distribution_id').html(distributionHtml);
                        $('#distribution_technician_id').html(technicianHtml);
                    }else{
                        distributionHtml += '';
                        $('#distribution_id').html(distributionHtml);
                        $('#distribution_technician_id').html(technicianHtml);
                    }
                    $("#distribution_id").trigger("change");
                }
            });
        });

        //点击配送站联动获得配送员
        $(document).on('change', '#distribution_id', function() {

            $('#distribution_technician_id').html('');
            var distribution_id = $('#distribution_id').children('option:selected').val();
            var technicianHtml = '<option value="">请选择</option>';
            $.ajax({
                type: "post",
                url: "/invokingAjax-comm/bill/distribution.ajax?operFlg=3",
                dataType: "json",
                data: {distribution_id: distribution_id},
                success: function( o ) {
                    if(o.code ==200 && o.data != null){
                        $.each(o.data, function(i,val){
                            technicianHtml +='<option value="'+val.distribution_technician_id+'">'+val.distribution_technician_name+'</option>';
                        });
                        $('#distribution_technician_id').html(technicianHtml);
                    }else{
                        technicianHtml += '';
                        $('#distribution_technician_id').html(technicianHtml);
                    }
                }
            });
        });

    });



</script>

</body>

</html>
